/*
 * This file is part of the OdinMS Maple Story Server
 * Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
 *                    Matthias Butz <matze@odinms.de>
 *                    Jan Christian Meyer <vimes@odinms.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation. You may not use, modify
 * or distribute this program under any other version of the
 * GNU Affero General Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/** Borrowed from AzuraStory, thanks guys!
 *
 * @author DestinyFate
 *
 * Thief 4th Job Advancement
 * 2081400.js
 */

importPackage(net.sf.odinms.client);

var status = 0;
var job;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0 && status == 0) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
            if (!(cm.getJob().equals(MapleJob.HERMIT) ||
                cm.getJob().equals(MapleJob.CHIEFBANDIT) ||
                cm.getJob().equals(MapleJob.NIGHTLORD) ||
                cm.getJob().equals(MapleJob.SHADOWER))) {
                cm.sendOk("Why do you want to see me? There is nothing you want to ask me.");
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.NIGHTLORD)) {
                cm.sendNext( "You became the best thief #bNight Lord#k. Night Lord is good at using #bFake#k to avoid enemy's attack and #bNinja Ambush#k to call hidden colleagues. It attacks the blind side of enemy. " );
                //                cm.sendNext( "This is not all about Night Lord. Night Lord is good at fast war. It can throw many stars at one time and may beat off plenty of enemies at once." );
                //                cm.sendNext( "Don't forget that it all depends on how much you train." );
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.SHADOWER)) {
                cm.sendNext( "You became the best thief #bShadower#k. Night Lord is good at using #bFake#k to avoid enemy's attack and #bNinja Ambush#k to call hidden colleagues. It attacks the blind side of enemy. " );
                //                cm.sendNext( "This is not all about Shadower. Shadower is good at sudden attack. It can attack enemies before they notice and even beat them locked in the darkness." );
                //                cm.sendNext( "Don't forget that it all depends on how much you train." );
                cm.dispose();
                return;
            }
            if (cm.getPlayer().getLevel() >= 120) {
                if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.HERMIT)) {
                    cm.sendSimple("You're qualified to be a true thief. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Night Lord.#l\r\n#b#L1#  Let me think for a while.#l");
                } else if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.CHIEFBANDIT)) {
                    cm.sendSimple("ou're qualified to be a true thief. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Shadower.#l\r\n#b#L1#  Let me think for a while.#l");
                } else {
                    cm.sendOk("Hmm...You have too many #bSP#k. You can't make the 4th job advancement with too many SP left.");
                    cm.dispose();
                    return;
                }
            } else {
                cm.sendOk("You're still weak to go to thief extreme road. If you get stronger, come back to me.");
                return;
            }
        } else if (status == 1) {
            if (selection == 0 && cm.getJob().equals(MapleJob.HERMIT)) {
                cm.changeJob(MapleJob.NIGHTLORD);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.sendNext("You became the best thief, the position of #bNight Lord#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else if (selection == 0 && cm.getJob().equals(MapleJob.CHIEFBANDIT)) {
                cm.changeJob(MapleJob.SHADOWER);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.sendNext("You became the best thief, the position of #bShadower#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else {
                cm.sendOk("You don't have to hesitate....You passed all tests. Whenever you decide, talk to me. If you're ready, I'll let you make the 4th job advancement.");
                cm.dispose();
            }
        }
    }
}